{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "img = cv2.imread('image0.jpg',1)\n",
    "# 第一个参数 写入的文件名 第二个参数为文件数据（已经解码后的数据，即图片的原始数据（经过imread处理））\n",
    "# 第三个参数使图像保存的质量参数范围从0-100，数字越大质量越高，这里是进行了有损压缩，以牺牲图片质量为代价进行压缩\n",
    "cv2.imwrite('imageTest.jpg',img,[cv2.IMWRITE_JPEG_QUALITY,50])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# jpg是有损压缩，png是无损压缩。同时png相比于jpg还多了一个透明度属性\n",
    "img = cv2.imread('image0.jpg',1)\n",
    "# 第三个参数为压缩比，数字越小压缩比越低。这一点与jpg相反。其压缩范围为0-9。jpg为0-100\n",
    "cv2.imwrite('imageTest.png',img,[cv2.IMWRITE_PNG_COMPRESSION,9])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
